/*
 * 产品查询
 * 参数   交易码：trancode=13121
 * 
 * 
 * @author alern2008@gmail.com
 * @系统名称：定制化辅助生成制造系统
 */

package org.ccams.tran;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.ccams.domain.TGoods;
import org.ccams.util.PageParameter;
import org.ccams.util.Utils;
/**
 * 查询功能菜单交易
 * @author liuguangshuai@gmail.com
 * @系统名称：定制化辅助生成制造系统
 * @时间：Aug 16, 2008
 */
public class Tran13121 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int limit = Integer.parseInt(request.getParameter("limit"));
		int start = Integer.parseInt(request.getParameter("start"));
		String keyWords = (String)request.getParameter("keywords");//查询关键字
		PageParameter page = new PageParameter();
		page.setLimit(limit);
		page.setStart(start);
		page.setKeyWords("%"+keyWords+"%");
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		//定义一个数组存放返回值
		ArrayList<TGoods> al = new ArrayList<TGoods>();
		List<TGoods> list = getCcamsService().getTgoodsDao().getTGoodsByPageAndKey(page);
		int count = getCcamsService().getTgoodsDao().getTGoodsCountByKey("%"+keyWords+"%");
		for(TGoods t : list){
			TGoods u = new TGoods();
			  u.setGoodsid(t.getGoodsid());
	          u.setGoodsno(t.getGoodsno());
	          u.setGoodsname(t.getGoodsname());  
	          u.setSpec(t.getSpec());
	          u.setSpellcode(t.getSpellcode()); 
	          u.setUnit(t.getUnit());
	          u.setFzunit1(t.getFzunit1());
	          u.setFzxs1(t.getFzxs1());
	          u.setFzunit2(t.getFzunit2());
	          u.setFzxs2(t.getFzxs2());
	          u.setStrCreatedDate(Utils.datetimeToString(t.getCreateddate(), "yyyy-MM-dd")); 
	          u.setGoodstypeno(t.getGoodstypeno());       
	          u.setGoodsclassno(t.getGoodsclassno());    
	          u.setGoodskindno(t.getGoodskindno());          
	          u.setIndication(t.getIndication());           
	          u.setServicetext(t.getServicetext());           
	          u.setReftext(t.getReftext());
	          u.setClassname(t.getClassname());
	          u.setTypename(t.getTypename());
	          u.setKindname(t.getKindname());
	          u.setFilename(t.getFilename());
			  al.add(u);
		}
		JSONArray JsonArray = JSONArray.fromObject(al); //得到JSON数组 
		jsonMap.put("totalProperty", count);
        jsonMap.put("root", JsonArray);
        json.putAll(jsonMap);
	}
}
